package com.zhentao.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

/**
 * 用户表
 * @TableName yd_user
 */
@TableName(value ="yd_user")
@Data
public  class YdUser implements Serializable,UserDetails {
    /**
     * 主键
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    /**
     * 用户姓名--例如张三
     */
    @TableField(value = "username")
    private String username;

    /**
     * 登录用户名
     */
    @TableField(value = "nickname")
    private String nickname;

    /**
     * 登陆密码
     */
    @TableField(value = "password")
    private String password;

    /**
     * 是否经理，0否，1是
     */
    @TableField(value = "leader_flag")
    private String leaderFlag;

    /**
     * 职位
     */
    @TableField(value = "position")
    private String position;

    /**
     * 所属部门
     */
    @TableField(value = "department")
    private String department;

    /**
     * 电子邮箱
     */
    @TableField(value = "email")
    private String email;

    /**
     * 手机号码
     */
    @TableField(value = "phonenum")
    private String phonenum;

    /**
     * 是否为管理者 0==管理者 1==员工
     */
    @TableField(value = "ismanager")
    private Integer ismanager;

    /**
     * 是否系统自带数据 
     */
    @TableField(value = "isystem")
    private Integer isystem;

    /**
     * 状态，0：正常，1：删除，2封禁
     */
    @TableField(value = "Status")
    private Integer status;

    /**
     * 用户描述信息
     */
    @TableField(value = "description")
    private String description;

    /**
     * 备注
     */
    @TableField(value = "remark")
    private String remark;

    /**
     * 租户id
     */
    @TableField(value = "tenant_id")
    private Long tenantId;

    @TableField(exist = false)
    private static final long serialVersionUID = 1L;

    @TableField(exist = false)
    private List<String> perms;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        List<GrantedAuthority> list = new ArrayList<>();
        if(perms != null){
            for (String perm : perms) {
                SimpleGrantedAuthority simpleGrantedAuthority = new SimpleGrantedAuthority(perm);
                list.add(simpleGrantedAuthority);
            }
            return list;
        }
        return null;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}